package cn.bdqn.asecu.controller;

import cn.bdqn.asecu.service.MessageService;
import cn.bdqn.pojo.Message;
import cn.bdqn.pojo.User;
import cn.bdqn.vo.UserMessage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@Controller
public class MessageController {

    @Autowired
    MessageService messageService;

    @RequestMapping("article-list2")
    public String article_list2(Model model, HttpServletRequest request){
       User user= (User) request.getSession().getAttribute("user");
        List<UserMessage> messageList = messageService.getMessage(user.getId());
        model.addAttribute("messageList",messageList);
        return "article-list2";
    }

    @RequestMapping("delMessage")
    @ResponseBody
    public String delMessage(Integer[] ids){
        for (Integer id : ids) {
            System.out.println(ids);
        }
        messageService.delMessage(ids);
        return "200";
    }
    @RequestMapping("makeAsRead")
    @ResponseBody
    public String makeAsRead(Integer[] ids){
        messageService.makeAsRead(ids);
        return "200";
    }
}
